package com.slorgs.web.controller

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.slorgs.business.service.ApiService
import com.slorgs.infrastructure.dto.ApiGroupDTO
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.servlet.ModelAndView
import javax.annotation.Resource
import javax.servlet.http.HttpServletRequest

@Controller
@RequestMapping("/portal")
class PageViewController {

    @Resource
    var apiService: ApiService? = null

    @GetMapping("/index")
    fun index(): ModelAndView {
        return ModelAndView("index")
    }

    @GetMapping("/service")
    fun service(api: ApiGroupDTO?, page: Page<*>?, request: HttpServletRequest?): ModelAndView {
        val model = hashMapOf<String, Any>()
        val data = apiService?.apiList(api, page, request)?.data as Page<*>
        data.records?.let { model.put("apiData", it) }
        model["logo"] = "https://nieva.cn:8896/nieva-logo.png"
        model["pageSize"] = data.size
        model["current"] = data.current
        model["total"] = data.total
        return ModelAndView("service", model)
    }
}